package leetcode.Hot100;


import leetcode.ListNode;

/**
 * @author Cheng Jun
 * Description: 请输入描述
 * @version 1.0
 * @date 2021/11/10 14:22
 */
public class hasCycle {
    public static void main(String[] args) {

    }

    static boolean hasCycle(ListNode head) {
        if (head == null) {
            return false;
        }
        ListNode fast = head;
        ListNode slow = head;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast) {
                return true;
            }
        }
        return false;
    }
}
